const db = wx.cloud.database();
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        index: 0,
        index2: 0,
        index3: 0,
        nianfen: ['请选择年份'],
        diqu: ['请选择地区'],
        danwei: ['请选择单位'],
        phone: 0,
        theList: ''
    },
    bindPickerChange: function (e) {
        let num = e.detail.value;
        let that = this;
        console.log('nianfen发送选择改变，携带值为', that.data.nianfen[num]);
        this.setData({
            index: e.detail.value
        })
        wx.request({ //发送请求
            url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=37120&callback=?', //接收url
            data: {
                level: '2',
                grfiled: 'nianfen',
                grtext: that.data.nianfen[num]
            }, //接收参数
            success(res) {
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                }
                var list = [];
                for (var i in theJson.lists) { //循环写入下来框
                    list.push(theJson.lists[i].diqu)
                }
                that.setData({
                    diqu: list
                });
            }
        })
    },
    bindPickerChange2: function (e) {
        let num2 = e.detail.value;
        let that = this;
        console.log('diqu发送选择改变，携带值为', that.data.diqu[num2]);
        this.setData({
            index2: e.detail.value
        })
    },

    		
    onLoad: function (options) {
        var that = this;
        var phone = wx.getStorageSync('phone');
        console.log(options);
        that.setData({
          area: options.area,
          geneal: options.agent,
          page: options.page,
        })
      
        
        wx.request({ //发送请求
            url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=37120&callback=?', //接收url
            data: {
                level: '1',
                nianfen: ''
            }, //接收参数
            success(res) { //返回
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                }
                var list = [];
                for (var i in theJson.lists) { //循环写入下来框
                    list.push(theJson.lists[i].nianfen)
                }
                that.setData({
                    nianfen: list
                });
            }
        })
    },

    getPhoneNumber(e) {
        var that = this;
        wx.cloud.callFunction({
            name: 'getMobile',
            data: {
                weRunData: wx.cloud.CloudID(e.detail.cloudID),
            }
        }).then(res => {
            that.setData({
                phone: res.result,
            })
            console.log(res.result)
            wx.setStorageSync('phone', res.result)
            wx.request({ //发送请求
                url: 'https://zg99.offcn.com/index/chaxun/register?actid=37120&callback=?', //接收url
                data: {
                    phone: res.result,
                    fenxiao: that.data.area,
                    geneal: that.data.geneal,
                }, //接收参数
                success(res) {
                    console.log(res)
                    var jsonStr = res.data;
                    jsonStr = jsonStr.replace("(", "");
                    jsonStr = jsonStr.replace(")", "");
                    if (typeof jsonStr != 'object') {
                        jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                        var theJson = JSON.parse(jsonStr);
                    }
                    console.log(theJson)
                   
                }
            })

            wx.request({
                url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
                method: 'POST',
                data: {
                  activeId: 30,
                  mobile: res.result,
                  areaCode: that.data.area,
                  agent: that.data.geneal,
                  pageId: that.data.page
                },
                success: res => {
                  console.log(res);
                }
              })
      
        }).catch(err => {
            console.error(err);
        });

    },


    tijiao: function (res) {
        var that = this;
        var nianfen = that.data.nianfen[that.data.index];
        var diqu = that.data.diqu[that.data.index2];
        var danwei = that.data.danwei[that.data.index3];


        wx.request({ //发送请求
            url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=37120&callback=?",
            data: {
                nianfen: nianfen,
                diqu: diqu,
                danwei: danwei,
                limits: '100'
            }, //接收参数
            success(res) { //返回
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                    jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                    var theJson = JSON.parse(jsonStr);
                };
                console.log(theJson)
                that.setData({
                    theList: theJson.lists
                })
                console.log(that.data.theList)
            }
        })




    },

    

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        wx.setNavigationBarTitle({
            title: '青岛卫生招聘分数线查询'  //修改title
          })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        wx.hideHomeButton();
        wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline']
          });
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onshareTimeline(){
        return{
            title: '历年青岛卫生分数线查询',
            desc: '快来查询青岛历年卫生招聘合格分数线',
        }
    },
    onShareAppMessage: function () {
        return{
            title: '历年青岛卫生分数线查询',
            desc: '快来查询青岛历年卫生招聘合格分数线'
        }
    }
})